<template>
    <div>
      <el-card>
        <div style="font-size:20px;font-weight:bold;margin-bottom:20px;">添加慢性病信息</div>
        <el-form :model="form" :rules="rules" ref="form" label-width="120px">
          <el-form-item label="疾病名称" prop="diseaseName">
            <el-input v-model="form.diseaseName"/>
          </el-form-item>
          <el-form-item label="确诊日期" prop="diagnosisDate">
            <el-date-picker v-model="form.diagnosisDate" type="date" value-format="yyyy-MM-dd"/>
          </el-form-item>
          <el-form-item label="用药情况" prop="medications">
            <el-input v-model="form.medications"/>
          </el-form-item>
          <el-form-item label="管理方案" prop="managementPlan">
            <el-input v-model="form.managementPlan"/>
          </el-form-item>
          <el-form-item label="上次复查" prop="lastCheckupDate">
            <el-date-picker v-model="form.lastCheckupDate" type="date" value-format="yyyy-MM-dd"/>
          </el-form-item>
          <el-form-item label="下次复查" prop="nextCheckupDate">
            <el-date-picker v-model="form.nextCheckupDate" type="date" value-format="yyyy-MM-dd"/>
          </el-form-item>
          <el-form-item label="备注" prop="notes">
            <el-input v-model="form.notes" type="textarea"/>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submitForm">创建</el-button>
            <el-button @click="$router.back()">取消</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
  </template>
  
  <script>
  export default {
    data() {
      return {
        form: {
          diseaseName: '',
          diagnosisDate: '',
          medications: '',
          managementPlan: '',
          lastCheckupDate: '',
          nextCheckupDate: '',
          notes: ''
        },
        rules: {
          diseaseName: [{ required: true, message: '请输入疾病名称', trigger: 'blur' }],
          diagnosisDate: [{ required: true, message: '请选择确诊日期', trigger: 'change' }]
        }
      }
    },
    methods: {
      submitForm() {
        this.$refs.form.validate(valid => {
          if (!valid) return;
          this.axios.post('/api/health/chronic-disease/add', this.form).then(res => {
            if(res.data.success) {
              this.$message.success('添加成功');
              this.$router.push({ path: '/home', query: { tab: 'chronic-disease' } });
            } else {
              this.$message.error(res.data.message || '添加失败');
            }
          });
        });
      }
    }
  }
  </script>